package com.ke.controller;

import com.ke.pojo.BaseResp;
import com.ke.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author bochen
 */
@RestController
@RequestMapping("/cart")
@CrossOrigin(allowCredentials = "true")
public class CartController {
    @Autowired
    CartService cartService;
    @RequestMapping("/addCart/{pid}")
    public BaseResp addCart(@PathVariable("pid")Integer pid, HttpServletRequest request){
        Integer uid= new Integer(request.getAttribute("id").toString());
        return cartService.addCart(pid,uid);
    }
    @RequestMapping("/addCart10/{pid}")
    public BaseResp addCart10(@PathVariable("pid")Integer pid, HttpServletRequest request){
        Integer uid= new Integer(request.getAttribute("id").toString());
        return cartService.addCart10(pid,uid);
    }
    @RequestMapping("/findAll")
    public BaseResp findAll(HttpServletRequest request){
        Integer uid=new Integer((String) request.getAttribute("id"));
        return cartService.findAll(uid);
    }
    @RequestMapping("/deleteOneCart/{id}")
    public BaseResp deleteOneCart(@PathVariable("id")Integer pid,HttpServletRequest request){
        Integer uid=new Integer((String) request.getAttribute("id"));
        return cartService.deleteOneCart(pid,uid);
    }
    @RequestMapping("/deleteCart/{id}")
    public BaseResp deleteCart(@PathVariable("id")Integer pid,HttpServletRequest request){
        Integer uid=new Integer((String) request.getAttribute("id"));
        return cartService.deleteCart(pid,uid);
    }
    @RequestMapping("/deleteAll")
    public BaseResp deleteAll(HttpServletRequest request){
        Integer uid=new Integer((String) request.getAttribute("id"));
        return cartService.deleteAll(uid);
    }
}
